package com.yiwenup.struct._02_tree;

import com.yiwenup.struct._02_tree.bst.BinarySearchTree;
import com.yiwenup.struct._02_tree.bst.bbst.AVLTree;
import com.yiwenup.struct._02_tree.bst.bbst.RBTree;
import com.yiwenup.printer.BinaryTrees;
import com.yiwenup.struct._02_tree.trie.Trie;

public class Main {
    public static void main(String[] args) {
        test1();
//        test2();
//        test3();
//        test4();
//        test5();
    }

    private static void test5() {
        Trie<Integer> trie = new Trie<>();
        trie.add("cat", 1);
        trie.add("dog", 2);
        trie.add("catalog", 3);
        trie.add("cast", 4);
        trie.add("嘿嘿嘿", 5);
        System.out.println(trie.size());
        System.out.println(trie.startWith("c"));
        System.out.println(trie.startWith("ca"));
        System.out.println(trie.startWith("cat"));
        System.out.println(trie.startWith("cata"));
        System.out.println(trie.startWith("cass"));
        System.out.println(trie.get("嘿嘿嘿"));
        System.out.println(trie.remove("catalog"));
        System.out.println(trie.get("cast"));
//        System.out.println(trie.size());
    }

    private static void test4() {
        Integer[] ints = {
                55, 87, 56, 74, 96, 22, 62, 20, 70, 68, 90, 50
        };
        RBTree<Integer> rb = new RBTree<>();
        for (int i = 0; i < ints.length; i++) {
            rb.add(ints[i]);
        }
        BinaryTrees.println(rb);
        for (int i = 0; i < ints.length; i++) {
            rb.remove(ints[i]);
            BinaryTrees.println(rb);
        }
    }

    private static void test3() {
        Integer[] ints = {
                77, 5, 81, 8, 46, 10, 14, 72, 41, 95, 97, 3, 51, 68, 67, 96, 71
        };
        AVLTree<Integer> binarySearchTree = new AVLTree<>();
        for (Integer anInt : ints) {
            binarySearchTree.add(anInt);
        }
        BinaryTrees.println(binarySearchTree);
    }

    private static void test2() {
        Integer[] ints = {7, 4, 9, 2, 5};
        BinarySearchTree<Integer> binarySearchTree = new BinarySearchTree<>();
        for (Integer anInt : ints) {
            binarySearchTree.add(anInt);
        }
        BinaryTrees.println(binarySearchTree);
        System.out.println(binarySearchTree.height());
        System.out.println(binarySearchTree.height2());
        System.out.println(binarySearchTree.isComplete());
    }

    private static void test1() {
        Integer[] ints = {7, 4, 9, 2, 5, 8, 11, 3, 12, 1};
        BinarySearchTree<Integer> binarySearchTree = new BinarySearchTree<>();
        for (Integer anInt : ints) {
            binarySearchTree.add(anInt);
        }
        BinaryTrees.println(binarySearchTree);
        binarySearchTree.preorderTraversal(System.out::println);
        binarySearchTree.preorder(System.out::println);
        binarySearchTree.preorder2(System.out::println);
        System.out.println("-------------------");
        binarySearchTree.inorderTraversal(System.out::println);
        binarySearchTree.inorder(System.out::println);
        System.out.println("-------------------");
        binarySearchTree.postorderTraversal(System.out::println);
        binarySearchTree.postorder(System.out::println);
        System.out.println("-------------------");
        binarySearchTree.levelOrderTraversal(System.out::println);
    }
}
